package com.example.demorabbitmqlisten.rabbitmq;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class KeShiKuCunServiceImpl extends ServiceImpl<HaoCaiChuKuMapper,HaoCaiChuKuEntity> {
    @Autowired
    private HaoCaiChuKuMapper haoCaiChuKuMapper;
    public void save(String json){
        UploadHaoCaiChuKuVo vo = JSONUtil.toBean(json, UploadHaoCaiChuKuVo.class);
        System.out.println(vo);
        List<HaoCaiChuKuVo> list = vo.getList();
        List<HaoCaiChuKuEntity> data = list.stream().map(haoCaiChuKuVo -> {
            HaoCaiChuKuEntity haoCaiChuKuEntity = new HaoCaiChuKuEntity();
            haoCaiChuKuEntity.setAmount(new BigDecimal(haoCaiChuKuVo.getAmount()));
            haoCaiChuKuEntity.setQuantity(new BigDecimal(haoCaiChuKuVo.getQuantity()));
            haoCaiChuKuEntity.setUnitPrice(new BigDecimal(haoCaiChuKuVo.getUnitPrice()));
            haoCaiChuKuEntity.setAmount(new BigDecimal(haoCaiChuKuVo.getAmount()));
            haoCaiChuKuEntity.setSupplierCode(haoCaiChuKuVo.getSupplierCode());
            haoCaiChuKuEntity.setEntryStatus(haoCaiChuKuVo.getEntryStatus());
            haoCaiChuKuEntity.setEntryDate(haoCaiChuKuVo.getEntryDate());
            haoCaiChuKuEntity.setDeliveryNoteNo(haoCaiChuKuVo.getDeliveryNoteNo());
            haoCaiChuKuEntity.setConsumableCode(haoCaiChuKuVo.getConsumableCode());
            haoCaiChuKuEntity.setBatchNo(haoCaiChuKuVo.getBatchNo());
            haoCaiChuKuEntity.setCreator(haoCaiChuKuVo.getCreator());
            haoCaiChuKuEntity.setCreateDate(haoCaiChuKuVo.getCreateDate());
            haoCaiChuKuEntity.setUpdater(haoCaiChuKuVo.getUpdater());
            haoCaiChuKuEntity.setUpdateDate(haoCaiChuKuVo.getCreateDate());
            return haoCaiChuKuEntity;
        }).collect(Collectors.toList());
        this.saveBatch(data);
    }
}
